<?php
//################################################################
// Menu
//################################################################

    // include stylesheets
    $this->echoStylesheets();

    // output menu header
    $template_vars = array();
    echo $this->getTemplate('menu_start',$template_vars);

    // read menu categories
    $res_menu_categories = execute_query("SELECT categorieID, name FROM %PRE%menu WHERE itemID = 0 ORDER BY categorieID",$MySQL_DB);
    while($menu_categories = $res_menu_categories->fetch_object()) {

        // output categorie header
        $template_vars = array(
            'categorie_name'=>$indexLanguage->translation($menu_categories->name, 'menu', 1)
        );
        echo $this->getTemplate('menu_categorie',$template_vars);

        $res_menu_entries = execute_query("SELECT ID, link, name FROM %PRE%menu WHERE categorieID = ".$menu_categories->categorieID." and itemID != 0 ORDER BY itemID",$MySQL_DB);
        while($menu_entries = $res_menu_entries->fetch_object()) {

            $flag_echo_menu = 0;

            // get all usergroups
            $usergroups = $currentUser->getAllUsergroups();
            foreach($usergroups as $usergroupID) {
                // check if menu entry enabled for usergroup
                $res_check_menu = execute_query("SELECT menu_ID FROM %PRE%usergroups_has_menu WHERE usergroups_ID = ".$usergroupID." and menu_ID = ".$menu_entries->ID,$MySQL_DB);
                if($check_menu = $res_check_menu->fetch_object()) {
                    $flag_echo_menu = 1;
                }
            }

            // flag for output menu
            if($flag_echo_menu == 1) {

                // output menu entry
                $template_vars = array(
                    'name'=>$indexLanguage->translation($menu_entries->name, 'menu', 1),
                    'link'=>$menu_entries->link
                );
                echo $this->getTemplate('menu_entry',$template_vars);
            }
        }
    }

    // output menu end
    $template_vars = array();
    echo $this->getTemplate('menu_end',$template_vars);

?>